var vue = {};
var data = {};
var form = {};
vue.initialize = function() {
	data.verifySrc = "verify/get";
	data.message="";
	form.userName="";
	form.password="";
	form.verifyCode="";
	data.form = form;
	new Vue({
		el : "#container-wrap",
		data : data,
		methods : vue
	});
	Vue.nextTick(function() {
		$("#container-wrap").show();
		initBackground();
	});
};
vue.changeCode = function() {
	var time = new Date().getTime();
	var src = data.verifySrc + "?t=" + time;
	data.verifySrc = src;
};
vue.login=function(){
	if ($.trim(form.userName) == '') {
		data.message="请填写用户名！";
		$(".user-name").focus();
		return;
	}
	if ($.trim(form.password) == '') {
		data.message="请填写密码！";
		$(".password").focus();
		return;
	}
	if ($.trim(form.verifyCode) == '') {
		data.message="请填写验证码！";
		$(".verify-code").focus();
		return;
	}
	var $loginBtn = $(".submit-btn");
	var loginValue = $loginBtn.val();
	$loginBtn.val("登录中...");
	$loginBtn.attr('disabled', "true");
	util.post({
		url : "user/login",
		data : form,
		success : function(result) {
			data.message="";
			window.location.replace(result.redirectUrl);
			return;
		},
		fail : function(code, msg) {
			data.message=msg;
		},
		complete : function() {
			$loginBtn.removeAttr("disabled");
			$loginBtn.val(loginValue);
		}
	});
};
function checkBrowser() {
	var ua = navigator.userAgent.toLowerCase();
	var ie = /msie/.test(ua);
	if (ie) {
		var version = ua.match(/msie ([\d.]+)/)[1];
		var msg = "您正在使用石器时代的浏览器，为了更好的体验，赶快升级，做回现代人吧！";
		var IE = createUpgrade("IE");
		var Chrome = createUpgrade("Chrome");
		var Firefox = createUpgrade("Firefox");
		if (version < 8) {
			msg += "升级" + IE + "、";
		}
		msg += "安装" + Chrome + "、" + Firefox + "等现代浏览器";
		layer.tips(msg, '.login-panel', {
			tips : [ 3, '#5F9EA0' ],
			area : [ '320px', 'auto' ],
			time : 0
		});
		return false;
	}
	return true;
};
function createUpgrade(n) {
	return "<a class='upgrade' href='https://www.baidu.com/s?wd=" + n
			+ "' target='_bank'>" + n + "</a>";
};
function checkPC() {
	var ua = navigator.userAgent;
	var agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone",
			"iPad", "iPod");
	var flag = true;
	for (var i = 0; i < agents.length; i++) {
		if (ua.indexOf(agents[i]) > 0) {
			flag = false;
			break;
		}
	}
	return flag;
};
function initBackground(){
	var images=[];
	var options={};
	images.push(ctx+"/assets/images/timg_new.jpg");
	options.fade=2000;
	options.duration=5000;
	$.backstretch(images,options);
};
function initialize() {
	if (!checkPC()) {
		util.warning("请在电脑端打开！");
		return;
	} else {
		if(checkBrowser()){
			vue.initialize();
		}
	}
};
